package cn.gok.shiro.service.impl;

import cn.gok.shiro.dao.UserDao;
import cn.gok.shiro.entity.Perms;
import cn.gok.shiro.entity.Role;
import cn.gok.shiro.entity.User;
import cn.gok.shiro.service.UserService;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: LKSV
 * @Description:
 * @Date:Created in 19:45 2021/8/19
 */
@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {
    @Resource
    UserDao userDao;

    @Override
    public void register(String username,String password) {
        Md5Hash md5Hash = new Md5Hash(password,"",1024);
        password=md5Hash.toHex();
        userDao.save(username,password);
    }

    @Override
    public User findByUserName(String username) {
        return userDao.findByUserName(username);
    }

    @Override
    public List<Perms> findPermsByRoleId(int id) {
        return userDao.findPermsByRoleId(id);
    }

    @Override
    public List<Role> findRolesByUserName(String username) {
        return userDao.findRolesByUserName(username);
    }
}
